package com.wicket.okrcomponent.biz.service.nb;

import cn.hutool.core.bean.BeanUtil;
import com.wicket.okrcomponent.common.exception.BizException;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import com.wicket.okrcomponent.biz.service.dto.req.ImplementTenReceivingFieldReqDto;
import com.wicket.okrcomponent.biz.service.dto.res.ImplementTenReceivingFieldRespDto;
import com.wicket.okrcomponent.biz.service.dto.req.ImplementTimeFormatConversionReqDto;
import com.wicket.okrcomponent.biz.service.dto.res.ImplementTimeFormatConversionRespDto;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

/**
 * @author ： 手工接入方法
 * @since 2022/5/28 15:32
 *
 *
 * @version 1.0
 */
@Service
public class NbDashboradStandardData {
/**
      * code:receptionService
      * name:M2接收入参字段
      * desc:undefined
      * gen by moon at 6/8/2024, 8:05:10 PM
      * 
      **/
     @Trace(operationName = "M2接收入参字段")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementTenReceivingFieldRespDto implementTenReceivingField(ImplementTenReceivingFieldReqDto reqDto) {
         return BeanUtil.toBean(reqDto, ImplementTenReceivingFieldRespDto.class);
      }
/**
      * code:timeFormatConversion
      * name:M2标准时间格式YYYY-MM-DD 00:00:00
      * desc:undefined
      * gen by moon at 7/3/2024, 8:16:32 PM
      *
      **/
     @Trace(operationName = "M2标准时间格式YYYY-MM-DD 00:00:00")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementTimeFormatConversionRespDto implementTimeFormatConversion(ImplementTimeFormatConversionReqDto reqDto) {
         System.out.println("M2标准时间格式,执行开始,入参时间为:"+reqDto.getComTxtField());
         ImplementTimeFormatConversionRespDto retData = new ImplementTimeFormatConversionRespDto();
         // 输入日期格式
         SimpleDateFormat inputFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
         inputFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai")); // 或者其他你期望的时区

         // 输出日期格式
         SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
         outputFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai")); // 或者其他你期望的时区
         Date date = null;
         String outputDateStr = null;

         try {
             // 解析输入字符串为日期对象
             date = inputFormat.parse(reqDto.getComTxtField());
             // 格式化日期对象为输出格式的字符串
             outputDateStr = outputFormat.format(date);
             retData.setComTxtField(outputDateStr);
         } catch (ParseException e) {
             System.out.println("M2标准时间格式:" + e);
             throw new BizException("-1","时间转换异常:"+e,false);
         }
         System.out.println("M2标准时间格式,执行结束");
         return retData;
      }
  //手工接入方法
}
